<header class="layout head padding-small">
    <a href="javascript:pageBack();" class="hBack float-left"></a>
    <h4 class="hTxt float-left text-center text-white">找回密码（第二步）</h4>
    <a href="javascript:;" id="btnJdkey" class="hHlep float-right"></a>
</header>
<div class="margin bg-white padding radius-big">
    <!--找回密码的步骤S-->
    <div class="revise-mobile">
        <div class="step text-small">
            <!--正在那一步的添加类active  已经通过了的添加类complete-->
            <div class="step-bar complete " style="width:25%;"><span class="step-point icon-check"></span><span class="step-text">账号验证</span></span></div>
            <div class="step-bar active" style="width:25%;"><span class="step-point">2</span><span class="step-text">身份校验</span></div>
            <div class="step-bar" style="width:25%;"><span class="step-point">3</span><span class="step-text">新密码</span></div>
            <div class="step-bar" style="width:25%;"><span class="step-point">4</span><span class="step-text">成功</span></div>
        </div>
    </div>


    <!--步骤2S-->
    <div class="mod-second">
        <div>昵称：<span><?php echo $output['member']['member_name'];?></span></div>
        <div>请选择校验方式</div>
        <?php $valid_list = $output['valid_list'];?>
        <?php if(!empty($valid_list) && is_array($valid_list)){?>
        <div class="clearfix">
            <?php if(isset($valid_list['mobile'])){?>
            <a href="javascript:;" class="x49 padding text-center border border-blue radius-big ">
                <div id="sendMobileCode">
                <i class="icon-comment text-blue "></i>
                <span class="mobile"><?php echo memberModel::hidePartMobileOrEmail($valid_list['mobile']);?></span>
                <div>短信验证</div>
                </div>
                <div id="send_code_tip" style="display: none;">
                <!--发送后-->
                <i class="icon-comment text-blue "></i>
                <span id="mobile_text" class="mobile text-blue">60秒后</span>
                <div class="text-blue">重新发送</div>
                </div>
            </a>
            <?php }?>
            <?php if(isset($valid_list['email'])){?>
            <a href="javascript:;" id="sendMobileCode" class="x49 padding text-center border border-green radius-big ">
                <i class="icon-envelope-square text-green "></i>
                <span class="mailBox"><?php echo memberModel::hidePartMobileOrEmail($valid_list['email']);?></span>
                <div>邮箱验证</div>
            </a>
            <?php }?>
        </div>
        <?php }?>
        <div class="field">
            <form id="check_code" method="post" action="index.php?act=login&op=find_password_step3">
                <input type="text" name="code" id="code" placeholder="请输入验证码" class="border border-ef7f7e layout padding radius-big">
            </form>
        </div>
        <div><input type="button" id="submitCode" value="下一步" class="border-none bg-red text-white layout padding radius-big "></div>
    </div>
    <!--步骤2E-->

</div>

<script>
$(function(){

	
	//切换验证方式
	var valid_mode_selected = "<?php echo key($valid_list);?>";

    $("#valid_list").change(function(){

    	valid_mode_selected = $(this).find("option:selected").val();
        var valid_name_list = new Array();
        var valid_mode_value = new Array();
        valid_name_list["email"] = "已验证邮箱：";
        valid_name_list["mobile"] = "已验证手机：";
        valid_mode_value["email"] = "<?php echo memberModel::hidePartMobileOrEmail($valid_list['email']);?>";
        valid_mode_value["mobile"] = "<?php echo memberModel::hidePartMobileOrEmail($valid_list['mobile']);?>";
        
        $("#valid_item_name").html(valid_name_list[valid_mode_selected]);
        $("#valid_item_value").html(valid_mode_value[valid_mode_selected]);
        
        });

    //获取验证码
	$("#sendMobileCode").click(function(event){
		event.preventDefault();
	    var getLink = $(this);
	    var $send_code_tip = $("#send_code_tip #mobile_text");

	    if(getLink.attr("data-status") == "load"){
	        alert("请稍后再试");
	        return false;
		    }

	    var send_data = {};
	    send_data.valid_mode = valid_mode_selected;
	    send_data.member_id = <?php echo $output['member']['member_id'];?>;
	    $.post("index.php?act=login&op=ajax_send_mobile_code", send_data, function(data){
	    	   if(!data.rs){
		    	   alert(data.msg);
		    	   }
	    	   else{
		    	   var tmpHtml = '';
		    	   var time = 60;
	    		   var countTime = setInterval(function(){
                       $('#send_code_tip').show();
                		    		    time--;

                		    		    if(time == 0){
                		    		    	$send_code_tip.html("");
                		    		    	tmpHtml = "获取短信验证码";
                    		    		    getLink.show().html(tmpHtml);
                    		    		    getLink.attr("data-status", "");                    		    		    
                		    		    	clearInterval(countTime);
                                            $('#sendMobileCode').show();
                                            $('#send_code_tip').hide();
                		    		    	return false;
                    		    		    }

                		    		    tmpHtml = "<b>" + time + " </b>秒后";
                		    		    $send_code_tip.html(tmpHtml);
                		    		    getLink.hide();
                		    		    getLink.attr("data-status", "load");
                		    		    }, 1000);
		    	   }	   
	    	   },"json");
    });

    //提交验证码
    $("#submitCode").click(function(event){
        event.preventDefault();
        
        var code = $("input[name='code']");

        if(code.val().length < 1){
            alert("请填写校验码");
            code.focus();
            return false;
        }

        $.post("index.php?act=login&op=check_find_password_code", {code:code.val()}, function(data){
	    	   if(!data.rs){
		    	   alert(data.msg);
		    	   return false;
		       }else{
		    	   $("#check_code").submit();
			   }
            }, "json");
        });    
});

</script>
